/**
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */

package org.openmrs.module.datalogging.configuration;

import org.openmrs.BaseOpenmrsMetadata;
import org.openmrs.module.datalogging.enums.EventType;

import java.util.HashSet;
import java.util.Set;

/**
 * <p>
 * Event is an object that will store the definition of event that will trigger logging process
 * Supported event current are: encounter created, obs created and rule executed
 * </p>
 * <p>
 * Every event definition will have:
 * <ul>
 * <li>eventType: describing the type of the event that will trigger logging</li>
 * <li>evenFilter: filter that will narrow down the event that will trigger logging. The format for even filter is a key1=value1,value2 where the
 * key is the property name on which the filter will be applied (e.g. location on encounter)</li>
 * <li>variables: list of element from the triggering event that will be logged</li>
 * </ul>
 * </p>
 * <p>
 * Example use case: we would like to log every test ordered on every encounter created in location x.
 * To achieve this we will create event with event type "encounter created" and the filter would be "location=location x"
 * with variable "concept=test ordered"
 * </p>
 */
public class Event extends BaseOpenmrsMetadata {

	private Integer eventId;

	private String description;

	private EventType eventType;

	private String eventFilter;

	private Set<Variable> variables;

	private Boolean active = Boolean.TRUE;

	/**
	 * @see org.openmrs.OpenmrsObject#getId()
	 */
	@Override
	public Integer getId() {
		return getEventId();
	}

	/**
	 * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
	 */
	@Override
	public void setId(Integer id) {
		setEventId(id);
	}

	/**
	 * Return the value of the eventId
	 *
	 * @return the eventId
	 */
	public Integer getEventId() {
		return eventId;
	}

	/**
	 * Set the eventId with the eventId value
	 *
	 * @param eventId the eventId to set
	 */
	public void setEventId(Integer eventId) {
		this.eventId = eventId;
	}

	/**
	 * Return the value of the triggeringEvent
	 *
	 * @return the triggeringEvent
	 */
	public EventType getEventType() {
		return eventType;
	}

	/**
	 * Set the triggeringEvent with the triggeringEvent value
	 *
	 * @param eventType the triggering event type to set
	 */
	public void setEventType(EventType eventType) {
		this.eventType = eventType;
	}

	/**
	 * Return the value of the name
	 *
	 * @return the name
	 */
	@Override
	public String getName() {
		return super.getName();
	}

	/**
	 * Set the name with the name value
	 *
	 * @param name the name to set
	 */
	@Override
	public void setName(String name) {
		super.setName(name);
	}

	/**
	 * Return the value of the description
	 *
	 * @return the description
	 */
	@Override
	public String getDescription() {
		return description;
	}

	/**
	 * Set the description with the description value
	 *
	 * @param description the description to set
	 */
	@Override
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Return the value of the eventFilter
	 *
	 * @return the eventFilter
	 */
	public String getEventFilter() {
		return eventFilter;
	}

	/**
	 * Set the eventFilter with the eventFilter value
	 *
	 * @param eventFilter the eventFilter to set
	 */
	public void setEventFilter(String eventFilter) {
		this.eventFilter = eventFilter;
	}

	/**
	 * Return the value of the variables
	 *
	 * @return the variables
	 */
	public Set<Variable> getVariables() {
		return variables;
	}

	/**
	 * Set the variables with the variables value
	 *
	 * @param variables the variables to set
	 */
	public void setVariables(Set<Variable> variables) {
		this.variables = variables;
	}

	/**
	 * @param variable
	 */
	public void addVariable(Variable variable) {
		if (variables == null)
			variables = new HashSet<Variable>();
		variables.add(variable);
	}

	/**
	 * Return the value of the active
	 *
	 * @return the active
	 */
	public Boolean getActive() {
		return active;
	}

	/**
	 * Set the active with the active value
	 *
	 * @param active the active to set
	 */
	public void setActive(Boolean active) {
		this.active = active;
	}
}
